<template>
  <c-form-dialog
    ref="form"
    :visible.sync="innerVisible"
    :form-items="formItems"
    :form-data="formData"
    :table-name="tableName"
    table-id=""
    @close="handleClose"
    :before-save="handleBeforeSave"
  ></c-form-dialog>
</template>

<script>
export default {
  components: {},
  props: {
    visible: Boolean,
    formData: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      innerVisible: false,
      tableName: 'industrial_class',
      formItems: [
        {
          tag: 'input',
          itemAttrs: {
            label: '分类名称',
          },
          attrs: { key: 'ind_class_name', value: '', placeholder: '请输入分类名称' },
        },
      ],
    }
  },
  computed: {
    code() {
      return this.formData.ind_class_code
    },
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
  },
  created() {},
  mounted() {},
  methods: {
    handleBeforeSave(model) {
      if (!this.code) {
        return
      }
      this.$api.updateDataBody('credit', this.tableName, { 'ind_class_code.eq': this.code }, model)
    },
    handleClose() {
      this.$emit('update:visible', false)
    },
    handleSuccess(res) {
      this.$emit('success', res)
    },
  },
}
</script>

<style lang="scss" scoped></style>
